import React from 'react';
import { Button, Modal, Tooltip } from 'antd';
import { WeaTab, WeaTop, WeaLocaleProvider,WeaDialog,WeaButtonIcon  } from 'ecCom';
import { inject, observer } from 'mobx-react';
import ExportList from "./ExportList";
import ExportLogList from "./ExportLogList";
import AddExportPermissions from "./AddExportPermissions";
import { doConfirm, getSearchs, setModal } from "../../util/BlogUtil";
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 考核设置
 * jiansong 2019/6/18
 */
@inject('exportBlogListStore')
@observer
export default class BlogExportIndex extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            visible: false, 
        }
    }


    render() {
        const {
            specifyShareTable,
            getSpecifyShareTable,
            searchAdForShareTable,
            exportLogListIsShow,
            searchAdForShareLogTable,
            setExportLogListIsShow,
            setObjShow,
            batchDel,
            isShowBatch
          } = this.props.exportBlogListStore;
        const { form, show, conditioninfo} = searchAdForShareTable;
        const { formLog, showLog, conditioninfoLog} = searchAdForShareLogTable;
      

        return (
            <div>
                {/* <WeaTop
                    iconBgcolor='rgb(150, 53, 138)'
                    buttons={this.getButton()}
                    showDropIcon={true}
                    dropMenuDatas={this.getMenu()}
                /> */}

                <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@v4ugk5`}
                    keyParam="viewcondition"
                    countParam="groupid"
                    searchType={["advanced"]}
                    buttons={[
                        <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@mlhvgx@primary`} buttonType="add" type="primary" onClick={() =>  setObjShow(true)} />,
                        isShowBatch?
                        <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@1aupu1@showConfirm`} style={{marginRight:'15px'}}  onClick={() => this.showConfirm()} buttonType="del"  type="primary" />:
                        <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@naue43@del`} style={{marginRight:'15px'}} buttonType="del" disabled  type="primary" />
                      ]}
                    searchsAd={getSearchs(form, conditioninfo, false, 2)}
                    showSearchAd={show}
                    buttonsAd={this.getTabButtonsAd()}
                    setShowSearchAd={() => (searchAdForShareTable.show = !show)}
                    hideSearchAd={() => (searchAdForShareTable.show = false)}
                    searchsBaseValue={
                    (searchAdForShareTable.form.isFormInit &&
                        searchAdForShareTable.form.getFormParams() &&
                        searchAdForShareTable.form.getFormParams().content) ||
                    ""
                    }
                    onSearch={() => {
                        getTableDatas();
                    }}
                    onSearchChange={value => {
                         form.updateFields({ content: value });
                    }}
                />
                <ExportList ecId={`${this && this.props && this.props.ecId || ''}_ExportList@0wcydn`} menu={this.getMenu()} />
                <AddExportPermissions ecId={`${this && this.props && this.props.ecId || ''}_AddExportPermissions@kel4jy`}/>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@hxfv9m`}
                    onCancel={() =>
                        setExportLogListIsShow(false)
                    }
                    title={getLabel(83, '日志')}
                    visible={exportLogListIsShow}
                    style={{ width: 1000, height: 600 }}
                    hasScroll
                    >
                     <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@fjiajs`}
                    keyParam="viewcondition"
                    countParam="groupid"
                    searchType={["advanced"]}
                    searchsAd={getSearchs(formLog, conditioninfoLog, false, 2)}
                    showSearchAd={showLog}
                    buttonsAd={this.getTabLogButtonsAd()}
                    setShowSearchAd={() => (searchAdForShareLogTable.showLog = !showLog)}
                    hideSearchAd={() => (searchAdForShareLogTable.showLog = false)}
                    searchsBaseValue={
                    (searchAdForShareLogTable.formLog.isFormInit &&
                        searchAdForShareLogTable.formLog.getFormParams() &&
                        searchAdForShareLogTable.formLog.getFormParams().content) ||
                    ""
                    }
                    onSearch={() => {
                        getTableLogDatas();
                    }}
                    onSearchChange={value => {
                         form.updateFields({ content: value });
                    }}
                />
                 <ExportLogList ecId={`${this && this.props && this.props.ecId || ''}_ExportLogList@xdpuf3`}/>
                </WeaDialog>


               
            </div>
        )
    }

    showConfirm() {
        const {
            batchDel
          } = this.props.exportBlogListStore;
        Modal.confirm({
          title: getLabel(558,'提示') ,
          content: getLabel(385624, '确定要删除选择的记录吗？'),
          onOk() {
            batchDel();
          },
          onCancel() {}
        });
    }
    getButton() {
        const {
            setObjShow,
            isShowBatch
          } = this.props.exportBlogListStore;
        let buttons = [];
        buttons = [(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@wre1v2@primary`} title={getLabel(384113, '添加')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bbb0gl@add`} type='primary' onClick={() =>  setObjShow(true)}>{getLabel('384113', '添加')}</Button></Tooltip>),
        (<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@rjmz29@batchdel`} title={getLabel(32136,'批量删除')}>
            {isShowBatch?<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@gv2qda@batchdel`} type='primary'    onClick={() => this.showConfirm()}>{getLabel(32136, '批量删除')}</Button>:
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@6zm2og@batchdel`} type='primary' disabled  onClick={() => this.showConfirm()}>{getLabel(32136, '批量删除')}</Button>}
            </Tooltip>)]
        return buttons;
    };

    getTabButtonsAd() {
        const {
            getTableDatas,
            searchAdForShareTable
        } = this.props.exportBlogListStore;
        const { form } = searchAdForShareTable;
        return [
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@wldz7n@primary`}
                type="primary"
                onClick={() => {
                    getTableDatas();
                    searchAdForShareTable.show = false;
                }}
            >
                {getLabel(197, "搜索")}
            </Button>,
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@35hhyr@search`} type="ghost" onClick={() => form.reset()}>
                {getLabel(27088, "重置")}
            </Button>,
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mo1izx@cancel`} type="ghost" onClick={() => (searchAdForShareTable.show = false)}>
                {getLabel(31129, "取消")}
            </Button>
        ];
    }


    getTabLogButtonsAd() {
        const {
            getTableLogDatas,
            searchAdForShareLogTable
        } = this.props.exportBlogListStore;
        const { formLog} = searchAdForShareLogTable;
        return [
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bpeomn@$primary`}
                type="primary"
                onClick={() => {
                    getTableLogDatas();
                    searchAdForShareLogTable.showLog = false;
                }}
            >
                {getLabel(197, "搜索")}
            </Button>,
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@p7ko8a@reset`} type="ghost" onClick={() => formLog.reset()}>
                {getLabel(27088, "重置")}
            </Button>,
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qmzv9q@cancel`} type="ghost" onClick={() => (searchAdForShareLogTable.showLog = false)}>
                {getLabel(31129, "取消")}
            </Button>
        ];
    }

    getMenu() {
            // const { baseSettingStore } = this.props;
            // const { baseSettingOperate, canedit, settingData: { resourcetype, id } } = baseSettingStore;
            // const { accessItemListStore } = this.props;
            const {
                setObjShow,
                batchDel,
                isShowBatch,
                setExportLogListIsShow
              } = this.props.exportBlogListStore;
            let menus = [];
            menus = [{
                key: '1',
                icon: <i className='icon-coms-tianjia' />,
                content: getLabel('384113', '添加'),
                onClick: () => setObjShow(true)
            }]
            menus.push({
                key: '2',
                icon: <i className="icon-coms-Batch-delete" />,
                content: getLabel('32136', '批量删除'),
                disabled:!isShowBatch?true:false,
                onClick:() =>this.showConfirm()
            })
            menus.push({
                key: '3',
                icon: <i className="icon-coms-Print-log" />,
                content: getLabel('83', '日志'),
                onClick: () => setExportLogListIsShow(true),
            })
        
        return menus;
    };

};